/*
 * SwingPasswordField.fx
 * Author : Yu Min-ting
 * Created on 2009-7-10, 12:45:27
 */

package com.sjtu.fx.tools;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javafx.ext.swing.SwingComponent;
import javax.swing.JComponent;
import javax.swing.JPasswordField;

public class SwingPasswordField extends SwingComponent {

    var passwordField: JPasswordField;

    public var text:String on replace {
        passwordField.setText(text)
    }
    public var action: function();
    public var columns:Number on replace {
        passwordField.setColumns(columns)
    }
    public var editable:Boolean on replace {
        passwordField.setEditable(editable)
    }

    public override function createJComponent():JComponent{
        passwordField = new JPasswordField();
        passwordField.setColumns(columns);
        passwordField.setEditable(editable);
        passwordField.setText(text);
        passwordField.addActionListener(
        ActionListener{
            public override function actionPerformed(e:ActionEvent){
                text = passwordField.getText();
                action();
            }

        }
        );
         passwordField.addKeyListener( KeyListener{
             public override function
            keyPressed(keyEvent:KeyEvent) {

            }

              public override function
            keyTyped(keyEvent:KeyEvent) {

            }

            public override function
            keyReleased( keyEvent:KeyEvent) {
               if (text != passwordField.getText())
                  text = passwordField.getText();

            }
 
        }
        );
        return passwordField;
    }
}

